*Duration of coholding, number of spells, amount of coholding in spell


********************************************************************************
*Mean duration of coholding

*Any individual x day
estpost summarize _seq if _end==1 & cohold_day==1, detail
est store w
esttab w using "Tables/DurationCoholding1_plain.tex", replace ///
collabels(none) ///
rename(_seq "Individual x day level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline


**********************************************************
*Table A11: Duration of Co-holding Spells
**********************************************************
*Single individual x day
estpost summarize _seq if _end==1 & cohold_day==1 & alwaysin2memberhh==0, detail
est store w
esttab w using "Tables/DurationCoholding1_plain_S.tex", replace ///
collabels(none) ///
rename(_seq "Single individual x day level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*Linked individual x day
estpost summarize _seq if _end==1 & cohold_day==1 & alwaysin2memberhh==1, detail
est store w
esttab w using "Tables/DurationCoholding1_plain_L.tex", replace ///
collabels(none) ///
rename(_seq "Linked individual x day level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*Household x day level
estpost summarize _seq_HH if _end_HH==1 & cohold_day_HH==1 & hh_edate_obs==1, detail
est store y
esttab y using "Tables/DurationCoholding1_HH_plain.tex", replace ///
collabels(none) ///
rename(_seq_HH "Household x day level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline


*Mean duration of coholding, different unit of analysis

*Any individual level
estpost summarize indmean_cohold_length if edate_id==1335, detail
est store x
esttab x using "Tables/DurationCoholding2_plain.tex", replace ///
collabels(none) ///
rename(indmean_cohold_length "Individual level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*Single individual level
estpost summarize indmean_cohold_length if edate_id==1335 & alwaysin2memberhh==0, detail
est store x
esttab x using "Tables/DurationCoholding2_plain_S.tex", replace ///
collabels(none) ///
rename(indmean_cohold_length "Single individual level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*Linked individual level
estpost summarize indmean_cohold_length if edate_id==1335 & alwaysin2memberhh==1, detail
est store x
esttab x using "Tables/DurationCoholding2_plain_L.tex", replace ///
collabels(none) ///
rename(indmean_cohold_length "Linked individual level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*Mean duration of coholding at the household level, considering positive durations of coholding only
estpost summarize HHmean_cohold_length if edate_id==1335 & hh_edate_obs==1, detail
est store z
esttab z using "Tables/DurationCoholding2_HH_plain.tex", replace ///
collabels(none) ///
rename(HHmean_cohold_length "Household level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*********************************************************************************
***Histogram duration of coholding at the x day level

recode _seq (40.0000001/100000000 = 47.5), gen(_seq_cat)
recode _seq_HH (40.0000001/100000000 = 47.5), gen(_seq_HH_cat)


**********************************************************
*Figure 3: Co-holding Spell Duration vs. Co-holding Frequency
*3B: Duration 
**********************************************************	
*Individual x day level
hist  _seq_cat if _end==1 & cohold_day==1, frac width(5) ///
fcolor(blue) lwidth(medium) lcolor(black) ///
title("Fraction of observations", place(left) size(large)) ///
ytitle("") ///
xtitle("Duration of coholding (in days)", size(large)) ///
ylabel(, labsize(medium) angle(0) format(%9.1fc)) ///
xlabel(0 5 10 15 20 25 30 35 40 47.5 ">40", labsize(medium)) ///
start(0)
graph export "Figures/DurationCoholdingIndividualXdayW10.pdf", replace
graph export "Figures/DurationCoholdingIndividualXdayW10.png", width(1800) height(1300) replace

*Single individual x day
hist  _seq_cat if _end==1 & cohold_day==1 & alwaysin2memberhh==0, frac width(5) ///
fcolor(blue) lwidth(medium) lcolor(black) ///
title("Fraction of observations", place(left) size(large)) ///
ytitle("") ///
xtitle("Duration of coholding (in days)", size(large)) ///
ylabel(, labsize(medium) angle(0) format(%9.1fc)) ///
xlabel(0 5 10 15 20 25 30 35 40 47.5 ">40", labsize(medium)) ///
start(0)
graph export "Figures/DurationCoholdingIndividualXdayW10_S.pdf", replace
graph export "Figures/DurationCoholdingIndividualXdayW10_S.png", width(1800) height(1300) replace

*Linked individual x day
hist  _seq_cat if _end==1 & cohold_day==1 & alwaysin2memberhh==1, frac width(5) ///
fcolor(blue) lwidth(medium) lcolor(black) ///
title("Fraction of observations", place(left) size(large)) ///
ytitle("") ///
xtitle("Duration of coholding (in days)", size(large)) ///
ylabel(, labsize(medium) angle(0) format(%9.1fc)) ///
xlabel(0 5 10 15 20 25 30 35 40 47.5 ">40", labsize(medium)) ///
start(0)
graph export "Figures/DurationCoholdingIndividualXdayW10_L.pdf", replace
graph export "Figures/DurationCoholdingIndividualXdayW10_L.png", width(1800) height(1300) replace

*Household x day
hist  _seq_HH_cat if _end_HH==1 & cohold_day_HH==1 & hh_edate_obs==1, frac width(5) ///
fcolor(blue) lwidth(medium) lcolor(black) ///
title("Fraction of observations", place(left) size(large)) ///
ytitle("") ///
xtitle("Duration of coholding (in days)", size(large)) ///
ylabel(, labsize(medium) angle(0) format(%9.1fc)) ///
xlabel(0 5 10 15 20 25 30 35 40 47.5 ">40", labsize(medium)) ///
start(0)
graph export "Figures/DurationCoholdingIndividualXdayW10_HH.pdf", replace
graph export "Figures/DurationCoholdingIndividualXdayW10_HH.png", width(1800) height(1300) replace


drop _seq_cat _seq_HH_cat

********************************************************************************
********************************************************************************
********************************************************************************

***Number of coholding spells

*Individual level
estpost summarize nr_spells if edate_id==1335, detail
est store z
esttab z using "Tables/NrSpellCoholding_plain.tex", replace ///
collabels(none) ///
rename(nr_spells "Any individual level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*Single individual level
estpost summarize nr_spells if edate_id==1335 & alwaysin2memberhh==0, detail
est store z
esttab z using "Tables/NrSpellCoholding_plain_S.tex", replace ///
collabels(none) ///
rename(nr_spells "Single individual level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*Linked individual level
estpost summarize nr_spells if edate_id==1335 & alwaysin2memberhh==1, detail
est store z
esttab z using "Tables/NrSpellCoholding_plain_L.tex", replace ///
collabels(none) ///
rename(nr_spells "Linked individual level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*Household level
estpost summarize nr_spells_HH if edate_id==1335 & hh_edate_obs==1, detail
est store z
esttab z using "Tables/NrSpellCoholding_HH_plain.tex", replace ///
collabels(none) ///
rename(nr_spells_HH "Household level") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline
 


**********************************************************
*Figure 3: Co-holding Spell Duration vs. Co-holding Frequency
* 3A: Spell Length vs. Frequency  
**********************************************************	
binscatter indmean_cohold_length nr_spells if edate_id == 1335, ///
mcolors(blue) line(qfit) lcolor(blue) ///
title("Duration of coholding (in days)", place(left) size(large)) ///
ytitle("") ///
xtitle("Number of coholding spells", size(large)) ///
ylabel(, labsize(medium) angle(0)) ///
xlabel(, labsize(medium)) ///
nquantiles(20) 
graph export "Figures/BinscatterDurationNumberSpellsIndividualLevel.pdf", replace
graph export "Figures/BinscatterDurationNumberSpellsIndividualLevel.png", width(1800) height(1300) replace

binscatter indmean_cohold_length nr_spells if edate_id == 1335 & alwaysin2memberhh==0, ///
mcolors(blue) line(qfit) lcolor(blue) ///
title("Duration of coholding (in days)", place(left) size(large)) ///
ytitle("") ///
xtitle("Number of coholding spells", size(large)) ///
ylabel(, labsize(medium) angle(0)) ///
xlabel(, labsize(medium)) ///
nquantiles(20) 
graph export "Figures/BinscatterDurationNumberSpellsIndividualLevel_S.pdf", replace
graph export "Figures/BinscatterDurationNumberSpellsIndividualLevel_S.png", width(1800) height(1300) replace

binscatter indmean_cohold_length nr_spells if edate_id == 1335 & alwaysin2memberhh==1, ///
mcolors(blue) line(qfit) lcolor(blue) ///
title("Duration of coholding (in days)", place(left) size(large)) ///
ytitle("") ///
xtitle("Number of coholding spells", size(large)) ///
ylabel(, labsize(medium) angle(0)) ///
xlabel(, labsize(medium)) ///
nquantiles(20) 
graph export "Figures/BinscatterDurationNumberSpellsIndividualLevel_L.pdf", replace
graph export "Figures/BinscatterDurationNumberSpellsIndividualLevel_L.png", width(1800) height(1300) replace

binscatter HHmean_cohold_length nr_spells_HH if hh_edate_obs==1 & edate_id==1335, ///
mcolors(blue) line(qfit) lcolor(blue) ///
title("Duration of coholding (in days)", place(left) size(large)) ///
ytitle("") ///
xtitle("Number of coholding spells", size(large)) ///
ylabel(, labsize(medium) angle(0)) ///
xlabel(, labsize(medium)) ///
nquantiles(20) 
graph export "Figures/BinscatterDurationNumberSpellsIndividualLevel_HH.pdf", replace
graph export "Figures/BinscatterDurationNumberSpellsIndividualLevel_HH.png", width(1800) height(1300) replace



********************************************************************************

*Coholding x spell level, any individual
estpost summarize cohold_amount_exp if ind_spell_obs==1, detail
est store x
esttab x using "Tables/UnnecOverdraftSpell.tex", replace ///
collabels(none) ///
rename(cohold_amount_exp "Any individual x spell") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*Coholding x spell level, single individual
estpost summarize cohold_amount_exp if ind_spell_obs==1 & alwaysin2memberhh==0, detail
est store x
esttab x using "Tables/UnnecOverdraftSpell_S.tex", replace ///
collabels(none) ///
rename(cohold_amount_exp "Single individual x spell") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*Coholding x spell level, linked individual
estpost summarize cohold_amount_exp if ind_spell_obs==1 & alwaysin2memberhh==1, detail
est store x
esttab x using "Tables/UnnecOverdraftSpell_L.tex", replace ///
collabels(none) ///
rename(cohold_amount_exp "Linked individual x spell") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline

*Coholding x spell level, households
estpost summarize cohold_amount_exp_HH if ind_spell_obs_HH==1 & hh_edate_obs==1, detail
est store x
esttab x using "Tables/UnnecOverdraftSpell_HH.tex", replace ///
collabels(none) ///
rename(cohold_amount_exp_HH "Household x spell") ///
cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1)) p75(fmt(1)) p90(fmt(1)) p95(fmt(1)) count(fmt(%15.0fc))") ///
nolabel nonumber nostar noobs nomtitle ///
booktabs fragment noline
